package com.lh.java.mongodb;

import java.util.Set;

import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;

public class TestCollections {	
	public static void main(String[] args) {
		DB db = MongoDbDateSorce.getDbInstance();
		Set<String> colls = db.getCollectionNames();
		for (String s : colls) {
		    System.out.println(s);
		}
		//system.indexes   things
		DBCollection coll = db.getCollection("lh");
		BasicDBObject doc = new BasicDBObject("_id", "MongoDB").
        append("type", "database").
        append("count", 1).
        append("info", new BasicDBObject("x", 203).append("y", 102));
		
		BasicDBObject doc2 = new BasicDBObject("_id", "MongoDBccc");
        coll.insert(doc2);
        coll.insert(doc2);
        DBCursor cursor = coll.find();       
        	try {
        		   while(cursor.hasNext()) {
        		       System.out.println(cursor.next());
        		   }
        		} finally {
        		   cursor.close();
        		}		
        DBCollection coll2 = db.getCollection("lh5");
        coll2.insert(doc2);
        System.out.println("lh5============");
        DBCursor cursor2 = coll2.find();       
    	try {
    		   while(cursor2.hasNext()) {
    		       System.out.println(cursor2.next());
    		   }
    		} finally {
    		   cursor2.close();
    		}		
        MongoDbDateSorce.close();



	}

}
